//
//  ActivityDetailCell.m
//  MJApp
//
//  Created by John on 15/5/17.
//  Copyright (c) 2015年 wangliang. All rights reserved.
//

#import "ActivityDetailCell.h"
#import "JoinInPersonCell.h"
@interface ActivityDetailCell()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UIImageView *bagImageView;
@property (weak, nonatomic) IBOutlet UIButton *joinIn;
@property (weak, nonatomic) IBOutlet UIButton *comment;
@property (weak, nonatomic) IBOutlet UILabel *commentNum;
@property (weak, nonatomic) IBOutlet UILabel *personHead;
@property (weak, nonatomic) IBOutlet UILabel *activityTime;
@property (weak, nonatomic) IBOutlet UILabel *activityDes;
@property (weak, nonatomic) IBOutlet UILabel *joinInNum;
@property (weak, nonatomic) IBOutlet UICollectionView *joinPersonCollectView;

@end

static NSString * ID = @"ActivityDetailCell";
static NSString * collectID = @"JoinInPersonCell";
@implementation ActivityDetailCell

- (void)awakeFromNib {
    // Initialization code
    self.joinIn.layer.cornerRadius = self.joinIn.frame.size.height*0.5;
    
    self.comment.layer.cornerRadius = self.comment.frame.size.height*0.5;
    
    
    [self.joinPersonCollectView registerNib:[UINib nibWithNibName:collectID bundle:nil] forCellWithReuseIdentifier:collectID];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
+(instancetype)cellForTableview:(UITableView *)tableview{
    ActivityDetailCell * cell
    = [tableview dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[NSBundle mainBundle]loadNibNamed:ID owner:nil options:nil].lastObject;
    }
    return cell;
//    return nil;1111111
}
- (IBAction)toJoinIn:(id)sender {
    if ([self.delegate respondsToSelector:@selector(joinActivityWithActivtyDic:)]) {
        [self.delegate joinActivityWithActivtyDic:self.infoDic];
    }
}
- (IBAction)toComment:(id)sender {
    if ([self.delegate respondsToSelector:@selector(commentActivityWithActivtyDic:)]) {
        [self.delegate commentActivityWithActivtyDic:self.infoDic];
    }
}
- (IBAction)checkUser:(id)sender {
    
    if ([self.delegate respondsToSelector:@selector(joinUserList:)]) {
        
        [self.delegate joinUserList:self.infoDic[@"join_users"]];
    }
}


- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return ((NSArray *)self.infoDic[@"join_users"]).count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    JoinInPersonCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:collectID forIndexPath:indexPath];
    cell.infoDic = self.infoDic[@"join_users"][indexPath.row];
    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if ([self.delegate respondsToSelector:@selector(checkUserInfo:)]) {
        
        [self.delegate checkUserInfo:self.infoDic[@"join_users"][indexPath.row]];
    }
    NSLog(@"%@",self.infoDic[@"join_users"][indexPath.row]);
}

- (void)setInfoDic:(NSDictionary *)infoDic{

    if (infoDic==nil) {
        return;
    }
    [super setInfoDic:infoDic];
    [self.bagImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kUrl,infoDic[@"detail"][@"back_img"]]] placeholderImage:nil];
    self.activityDes.text = infoDic[@"detail"][@"content"];
    self.joinInNum.text = [NSString stringWithFormat:@"%@人",infoDic[@"join_users_num"]];
    self.commentNum.text = [NSString stringWithFormat:@"%@",infoDic[@"discuss_num"]];
    self.personHead.text = [NSString stringWithFormat:@"%@",infoDic[@"join_users_num"]];
    [self.joinPersonCollectView reloadData];
}
@end
